﻿<%@ Page CodeFileBaseClass="AliCMS.Lib.SystemPageBase" %>
<script language="c#" runat="server">
protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	string and = String.Empty;

	#region 是否回收
	string isRecycled = Request.QueryString["IsRecycled"];
	if (isRecycled == null)
		condition.Append(and + Alias.Course.IsDeleted + "=false");
	else if (isRecycled != String.Empty)
		condition.Append(and + Alias.Course.IsDeleted + "=" + isRecycled);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否上架
	string isReleased = Request.QueryString["IsReleased"];
	if (isReleased == null)
		condition.Append(and + Alias.Course.IsReleased + "=true");
	else if (isReleased != String.Empty)
		condition.Append(and + Alias.Course.IsReleased + "=" + isReleased);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否推荐
	string isRecommended = Request.QueryString["IsRecommended"];
	if (!String.IsNullOrEmpty(isRecommended))
		condition.Append(and + Alias.Course.IsRecommended + "=" + isRecommended);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 媒体类型
	string mediaType = Request.QueryString["MediaType"];
	if (!String.IsNullOrEmpty(mediaType))
		condition.Append(and + Alias.Course.MediaType + "='" + mediaType + "'");
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 类别
	string categoryID = Request.QueryString["CategoryID"];
	if (!String.IsNullOrEmpty(categoryID))
	{
		if (Convert.ToBoolean(Request.QueryString["IncludeSubCategory"]))
		{
			condition.Append(and + Alias.Course.IncludeSubCategory + "=" + categoryID);
		}
		else
		{
			if (categoryID == "0")
				condition.Append(and + Alias.Course.CategoryID + " IS NULL");
			else
				condition.Append(and + Alias.Course.CategoryID + "=" + categoryID);
		}
	}
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 关键词
	string keyword = Request.QueryString["Keyword"];
	if (!String.IsNullOrEmpty(keyword))
	{
		condition.Append(and + "(" + Alias.Course.Name + " LIKE '%" + keyword + "%')");
	}
	#endregion
	
	return condition.ToString();
}

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.Course.InnerID + " DESC";
			break;
		case "2":
			sort = Alias.Course.InnerID + " ASC";
			break;
		case "3":
			sort = Alias.Course.Recommend + " DESC";
			break;
		case "4":
			sort = Alias.Course.Recommend + " ASC";
			break;
		case "5":
			sort = Alias.Course.HitCount + " DESC";
			break;
		case "6":
			sort = Alias.Course.HitCount + " ASC";
			break;
		case "7":
			sort = Alias.Course.SaleCount + " DESC";
			break;
		case "8":
			sort = Alias.Course.SaleCount + " ASC";
			break;
		case "9":
			sort = Alias.Course.CollectCount + " DESC";
			break;
		case "10":
			sort = Alias.Course.CollectCount + " ASC";
			break;
		case "11":
			sort = Alias.Course.UpdateTime + " DESC";
			break;
		case "12":
			sort = Alias.Course.UpdateTime + " ASC";
			break;
		default:
			sort = Alias.Course.InnerID + " DESC";
			break;
	}
	
	return sort;
}

protected string Move
{
	get
	{
		if ((Request.QueryString["Sort"] == "5" || Request.QueryString["Sort"] == "6") && Request.QueryString["IsRecommended"] == "true")
			return "MoveRecommend";
		else
			return "";
	}
}

protected bool ListByPicture
{
	get
	{
		if (Request.QueryString["ListByPicture"] != null)
			return Convert.ToBoolean(Request.QueryString["ListByPicture"]);
		else if (Request.Cookies["ListByPicture"] != null)
			return Convert.ToBoolean(Request.Cookies["ListByPicture"].Value);
		else
			return true;
	}
}
</script>
<section data-page="course_list" data-title="课程管理" data-move="<%=Move%>" data-lang="<%=ContentLang%>">
	<dl class="path1">
		<dt><span>您的位置：</span>课程管理</dt>
		<dd>
			<select data-class="<%=ContentLang%>Font" data-ali-widget="combo">
				<ali:List Mark="System" Object="Language" Source="Manager.Languages">
					<ali:Record>
						<%If Convert.ToString(Ab) == ContentLang%>
							<option value="<%=Ab%>" selected><%=[AliCMS.SystemModule.Alias.Language.Name + PageLang]%></option>
						<%Else%>
							<option value="<%=Ab%>"><%=[AliCMS.SystemModule.Alias.Language.Name + PageLang]%></option>
						<%EndIf%>
					</ali:Record>
				</ali:List>
			</select>
		</dd>
	</dl>
	<div class="ali-tabs sub-nav" data-height-style="fill" data-event="click">
		<div class="ali-tabs-header">
			<div class="ali-tabs-nav-container">
				<ul>
					<li class="ali-active"><a>课程列表</a></li>
					<li><a href="add.aspx?Lang=<%=ContentLang%>" target="ali-navtab">添加课程</a></li>
					<li><a href="stat_order_all.aspx?Lang=<%=ContentLang%>" target="ali-navtab">统计</a></li>
				</ul>				
			</div>
		</div>
		<div class="ali-tabs-body">
			<div class="ali-tabs-panel">
				<form action="?Lang=<%=ContentLang%>" class="search1">
					<select name="IsRecycled" data-class="<%=ContentLang%>Font" data-ali-widget="combo">
						<option value="">是否回收</option>
						<option value="false" selected>未回收</option>
						<option value="true">已回收</option>
					</select>
					<select name="IsReleased" data-class="<%=ContentLang%>Font" data-ali-widget="combo">
						<option value="">是否上架</option>
						<option value="false">未上架</option>
						<option value="true" selected>已上架</option>
					</select>
					<select name="IsRecommended" data-class="<%=ContentLang%>Font" data-ali-widget="combo">
						<option value="">是否推荐</option>
						<option value="false">未推荐</option>
						<option value="true">已推荐</option>
					</select>
					<select name="MediaType" data-class="<%=ContentLang%>Font" data-ali-widget="combo">
						<option value="">媒体类型</option>
						<option value="VIDEO">视频</option>
						<option value="AUDIO">音频</option>
						<option value="TEXT">图文</option>
					</select>
					<select name="CategoryID" data-class="<%=ContentLang%>Font" data-ali-widget="combo" data-tree="true" data-root="">
						<option data-item="" data-parent="" value="">所有类别</option>
						<option data-item="" data-parent="" value="0">未指定类别</option>
						<ali:Tree Object="Category">
							<ali:Record>
								<%If Convert.ToString(ID) == Request.QueryString["CategoryID"]%>
									<option data-item="<%=InnerID%>" data-parent="<%=ParentInnerID%>" value="<%=ID%>" selected><%=Name%></option>
								<%Else%>
									<option data-item="<%=InnerID%>" data-parent="<%=ParentInnerID%>" value="<%=ID%>"><%=Name%></option>
								<%EndIf%>
								<%=ChildRecords%>
							</ali:Record>
						</ali:Tree>
					</select>
					<label><input type="checkbox" name="IncludeSubCategory" class="ali-input" checked>子类</label>
					<label><input type="checkbox" name="ListByPicture" class="ali-input" checked>缩略图</label>
					<select name="Sort" class="ali-input" data-class="<%=ContentLang%>Font" data-ali-widget="combo">
						<option value="1">编号↓</option>
						<option value="2">编号↑</option>
						<option value="3">推荐↓</option>
						<option value="4">推荐↑</option>
						<option value="5">人气↓</option>
						<option value="6">人气↑</option>
						<option value="7">销量↓</option>
						<option value="8">销量↑</option>
						<option value="9">收藏↓</option>
						<option value="10">收藏↑</option>
						<option value="11">更新日期↓</option>
						<option value="12">更新日期↑</option>
					</select>
					<input name="Keyword" class="ali-input <%=ContentLang%>Font">
					<button type="submit" class="ali-button">搜索</button>
				</form>
				<ul class="toolbar1">
					<li class="select-all"><a><span>全选</span></a></li>
					<li class="select-reverse"><a><span>反选</span></a></li>
			
					<li class="recycle" data-operation="Recycle"><a><span>回收</span></a></li>
					<li class="delete" data-operation="Delete"><a><span>删除</span></a></li>
					<li class="recover" data-operation="Recover"><a><span>还原</span></a></li>
					<li class="release" data-operation="Release"><a><span>上架</span></a></li>
					<li class="unrelease" data-operation="UnRelease"><a><span>下架</span></a></li>
					<li class="recommend" data-operation="Recommend"><a><span>推荐</span></a></li>
					<li class="unrecommend" data-operation="UnRecommend"><a><span>取消推荐</span></a></li>
				</ul>
				<div class="content">
					<ali:List ID="List" Object="Course" Page="PageNumber" PageSize="20" Condition="Condition()" Sort="Sort()" Validate="True" />
						<%If ListByPicture%>
							<ali:List Object="Course" Source="List">
								<ali:Row MaxCol="5">
									<ul class="course-list">
										<ali:Col MaxRecord="1">
											<ali:Record>
												<li>
													<a href="edit.aspx?Lang=<%=ContentLang%>&ID=<%=InnerID%>" target="ali-navtab"><img src="<%=Thumbnail%>" /></a>
													<div class="<%=ContentLang%>Font"><a href="edit.aspx?ID=<%=InnerID%>" target="ali-navtab"><%=Name%></a><input type="checkbox" value="<%=InnerID%>"></div>
												</li>
											</ali:Record>
										</ali:Col>
									</ul>
								</ali:Row>
							</ali:List>
						<%Else%>
							<table data-ali-widget="grid" class="grid1">
								<thead>
									<tr>
										<th width="40">编号</th>
										<%If Move != ""%>
											<th width="120">
												<%If Request.QueryString["IsRecommended"] == "true"%>
													移动推荐
												<%EndIf%>
											</th>
										<%EndIf%>
										<th>名称</th>
										<th width="100">价格</th>
										<th width="100">会员免费</th>
										<th width="100">媒体类型</th>
										<th width="60">人气</th>
										<th width="60">收藏</th>
										<th width="60">销量</th>
									</tr>
								</thead>
								<tbody>
									<ali:List Object="Course" Source="List">
										<ali:Record>
											<tr data-id="<%=InnerID%>">
												<td><%=InnerID%></td>
												<%If Move != ""%>
													<td data-sort="<%=InnerID%>" data-name="<%=Name%>">移动</td>
												<%EndIf%>
												<td class="<%=ContentLang%>Font"><a href="edit.aspx?ID=<%=InnerID%>" target="ali-navtab"><%=Name%></a></td>
												<td>
													<%If Convert.ToString(TimeUnit) == "MONTH"%>
														<%=Price%>/<%=Convert.ToInt32(TimeAmount) == 1 ? "" : Convert.ToString(TimeAmount)%>月
													<%ElseIf Convert.ToString(TimeUnit) == "SEASON"%>
														<%=Price%>/<%=Convert.ToInt32(TimeAmount) == 1 ? "" : Convert.ToString(TimeAmount)%>季
													<%ElseIf Convert.ToString(TimeUnit) == "HALF_YEAR"%>
														<%=Price%>/<%=Convert.ToInt32(TimeAmount) == 1 ? "" : Convert.ToString(TimeAmount)%>半年
													<%ElseIf Convert.ToString(TimeUnit) == "YEAR"%>
														<%=Price%>/<%=Convert.ToInt32(TimeAmount) == 1 ? "" : Convert.ToString(TimeAmount)%>年
													<%Else%>
														<%=Price%>
													<%EndIf%>
												</td>
												<td><%If Convert.ToBoolean(IsMemberFree)%>是<%Else%>否<%EndIf%></td>
												<td><%If Convert.ToString(MediaType) == "VIDEO"%>视频<%ElseIf Convert.ToString(MediaType) == "AUDIO"%>音频<%Else%>图文<%EndIf%></td>
												<td><%=HitCount%></td>
												<td><%=CollectCount%></td>
												<td><%=SaleCount%></td>
											</tr>
										</ali:Record>
									</ali:List>
								</tbody>
							</table>
						<%EndIf%>
					</ali:List>
					<ali:Pagination Page="PageNumber" PageSize="20" RecordCount="List[RecordCount]">
						<div class="pagination1" data-page-number="<%=PageNumber%>" data-page-count="<%=PageCount%>" data-page-size="<%=PageSize%>">
							<div class="pagination1-left">
								共<b><%=PageCount%></b>页，每页显示
									<select name="PageSize" data-ali-widget="combo">
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
										<option value="200">200</option>
									</select>条，共<b><%=RecordCount%></b>条记录
							</div>
							<ul class="pagination1-right">
								<ali:FirstPage>
									<ali:Yes>
										<li><span><span class="first disabled">首页</span></span></li>
										<li><span><span class="prev disabled">上一页</span></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="1"><span class="first">首页</span></a></li>
										<li><a href="<%=PageNumber - 1%>"><span class="prev">上一页</span></a></li>
									</ali:No>
								</ali:FirstPage>
								<ali:CurrentPage Range="5">
									<ali:Yes>
										<li class="active"><span><%=Index%></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="<%=Index%>"><%=Index%></a></li>
									</ali:No>
								</ali:CurrentPage>
								<ali:LastPage>
									<ali:Yes>
										<li><span><span class="next disabled">下一页</span></span></li>
										<li><span><span class="last disabled">末页</span></span></li>
									</ali:Yes>
									<ali:No>
										<li><a href="<%=PageNumber + 1%>"><span class="next">下一页</span></a></li>
										<li><a href="<%=PageCount%>"><span class="last">末页</span></a></li>
									</ali:No>
								</ali:LastPage>
			
								<li class="go">
									<input type="text" name="PageNumber" value="1" size="4"><button></button>
								</li>
							</ul>
						</div>
					</ali:Pagination>
				</div>
			</div>
		</div>
		<div class="ali-tabs-bottom"><b></b></div>
	</div>
</section>